package fr.upmc.ta.android;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

public class VCircle extends View {

	private ArrayList<Point> points;
	private Paint paint;

	public VCircle(Context context) {
		super(context);
		paint = new Paint();

		points = new ArrayList<Point>();
		createCircle();
	}

	public void addPoint(Point p) {
		points.add(p);
		invalidate();
	}

	public void setPoint(Point point) {
		for (Point p : points) {
			if (p.getX() == point.getX() && p.getY() == point.getY()
					&& p.getCouleur() == point.getCouleur()) {
				//p.setCouleur(point.getCouleur());
				p.setX(point.getX());
				p.setY(point.getY());
				
				invalidate();
				
				return;
			}
		}
	}

	/** Dessinage des points avec le Canvas à l'intérieur */
	public void draw(Canvas canvas) {
		for (Point p : points) {
			paint.setColor(p.getCouleur());
			canvas.drawCircle((float) p.getX(), (float) p.getY(), 15, paint);
		}

		invalidate();
		super.draw(canvas);
	}

	private void createCircle() {
		addPoint(new Point(104, 64, Color.RED));
		addPoint(new Point(65, 220, Color.GREEN));
		addPoint(new Point(100, 200, Color.WHITE));
		addPoint(new Point(450, 300, Color.BLUE));
		addPoint(new Point(500, 70, Color.CYAN));
	}

}
